#include "file_class.h"

QDateTime fileTimeToQDateTime(const FILETIME& fileTime)
{
    qint64 rawTime = ((qint64)fileTime.dwHighDateTime << 32) + fileTime.dwLowDateTime;
    return QDateTime::fromMSecsSinceEpoch((rawTime - 116444736000000000) / 10000);
}

FileInfo::FileInfo() :
    name(""),
    type(""),
    path(""),
    filesize(0),
    creationTime(QDateTime::fromMSecsSinceEpoch(0)),
    lastAccessTime(QDateTime::fromMSecsSinceEpoch(0)),
    lastWriteTime(QDateTime::fromMSecsSinceEpoch(0)),
    numOfFile(0),
    numOfDir(0)
    {

    };

FileInfo::FileInfo(QString Name, QString Type, QString Path, qint64 Filesize, QDateTime CTime, QDateTime LATime, QDateTime LWTime) :
    name(Name),
    type(Type),
    path(Path),
    filesize(Filesize),
    creationTime(CTime),
    lastAccessTime(LATime),
    lastWriteTime(LWTime),
    numOfFile(1),
    numOfDir(0)
    {

    };

FileInfo::FileInfo(QString Name, QString Type, QString Path, QDateTime CTime, QDateTime LATime, QDateTime LWTime) :
    name(Name),
    type(Type),
    path(Path),
    filesize(1),
    creationTime(CTime),
    lastAccessTime(LATime),
    lastWriteTime(LWTime),
    numOfFile(0),
    numOfDir(1)
    {

    };

FileInfo::FileInfo(QString Type) :
    name(""),
    type(Type),
    path(""),
    filesize(0),
    creationTime(QDateTime::fromMSecsSinceEpoch(0)),
    lastAccessTime(QDateTime::fromMSecsSinceEpoch(0)),
    lastWriteTime(QDateTime::fromMSecsSinceEpoch(0)),
    numOfFile(0),
    numOfDir(0)
    {

    };

FileInfo::FileInfo(QString Name, QString Path) :
    name(Name),
    type("Disk"),
    path(Path),
    filesize(0),
    creationTime(QDateTime::fromMSecsSinceEpoch(0)),
    lastAccessTime(QDateTime::fromMSecsSinceEpoch(0)),
    lastWriteTime(QDateTime::fromMSecsSinceEpoch(0)),
    numOfFile(0),
    numOfDir(0)
    {

    };

void FileInfo::SizePlus(qint64 SizeToPlus) { filesize += SizeToPlus; }
void FileInfo::DirPlus(qint64 NumToPlus){numOfDir+=NumToPlus;}
void FileInfo::FilePlus(qint64 NumToPlus){numOfFile+=NumToPlus;}
void FileInfo::DirPlusPlus(){numOfDir=1;}

QString FileInfo::getName() { return name; }
QString FileInfo::getType() { return type; }
QString FileInfo::getPath() { return path; }
qint64 FileInfo::getSize() { return filesize; }
QDateTime FileInfo::getCreateTime() { return creationTime; }
QDateTime FileInfo::getAccessTime() { return lastAccessTime; }
QDateTime FileInfo::getWriteTime() { return lastWriteTime; }
qint64 FileInfo::getDirNum(){return numOfDir;}
qint64 FileInfo::getFileNum(){return numOfFile;}
